package com.woniuxy.repay.controller;

import com.woniuxy.entity.RepaymentManage;
import com.woniuxy.entity.RepaymentRegistration;
import com.woniuxy.repay.entity.PageBean;
import com.woniuxy.repay.service.RepaymentManageService;
import com.woniuxy.repay.service.RepaymentRegistrationService;
import com.woniuxy.utils.ResponseResult;
import com.woniuxy.utils.ResultStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author shichen
 * @create 2021-11-13-10:40
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/registration")
public class RepaymentRegistrationController {

    @Resource
    RepaymentRegistrationService repaymentRegistrationService;

    /**
     * 查询
     * @param pageIndex
     * @return
     */
    @GetMapping("/selectall/{pageIndex}")
    public ResponseResult selectAll(@PathVariable("pageIndex") Integer pageIndex, RepaymentRegistration repaymentRegistration) {
        // 校验
        log.debug("进入方法 selectAll request : {} ", repaymentRegistration);
        ResponseResult<PageBean> responseResult = null;
        try {
            PageBean pageBean = repaymentRegistrationService.selectByCondition(repaymentRegistration, pageIndex);
            responseResult=new ResponseResult(200,ResultStatus.HAVE_PERMS,"search repaymentRegistration success!",pageBean);
        } catch (Exception e) {
            e.printStackTrace();
            responseResult = new ResponseResult(500, ResultStatus.NO_PERMS, "search repaymentRegistration error", null);
        }

        log.debug("response : {} ", responseResult);


        return responseResult;
    }

    /**
     * 将传过来的信息，对数据库进行修改
     * @param repaymentRegistration
     * @return
     */
    @PutMapping("/update")
    public ResponseResult update(@RequestBody RepaymentRegistration repaymentRegistration){
        log.debug("request : {}", repaymentRegistration);
        ResponseResult responseResult = null;
        try {
            repaymentRegistrationService.updateByCondition(repaymentRegistration);
            responseResult=new ResponseResult(200,ResultStatus.NO_PERMS,"repaymentRegistration Update Success",null);
        } catch (Exception e) {
            e.printStackTrace();
            responseResult = new ResponseResult(500, ResultStatus.NO_PERMS, "repaymentRegistration Update Error", null);
        }
        return responseResult;
    }

    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody RepaymentRegistration repaymentRegistration){
        log.debug("request : {}", repaymentRegistration);
        ResponseResult responseResult = null;
        try {
            repaymentRegistrationService.insert(repaymentRegistration);
            responseResult=new ResponseResult(200,ResultStatus.NO_PERMS,"repaymentRegistration Insert Success",null);
        } catch (Exception e) {
            e.printStackTrace();
            responseResult = new ResponseResult(500, ResultStatus.NO_PERMS, "repaymentRegistration Insert Error", null);
        }
        return responseResult;
    }
}
